<!doctype html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport"
              content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>子路由</title>
        <style>
            .mychild {
                width: 600px;
                height: 400px;
                border: 5px dotted orange;
            }
        </style>
    </head>
    <body>
        <div id="app">
            <router-link to="/">首页</router-link>
            <router-link to="/about/child1">关于我们</router-link>
            <router-view></router-view>
        </div>
        <script src='../js/vue.js'></script>
        <script src="../js/vue-router.js"></script>
        <script>
            //父页
            let home = {
                template: `<div>首页</div>`
            }
            let about = {
                template: `<div>
                            关于我们
                            <router-link to="/about/child1">子页一</router-link>
                            <router-link to="/about/child2">子页二</router-link>
                            <div class="mychild">
                            <router-view></router-view>
                            </div>
                           </div>`
            }

            //子页
            let child1 = {
                template: `<div>子页一</div>`
            }
            let child2 = {
                template: `<div>子页二</div>`
            }

            let routes = [
                {"path": "/", component: home},
                {
                    "path": "/about", component: about,
                    children: [//定义子路由
                        {"path": "child1", component: child1},
                        {"path": "child2", component: child2},
                    ]
                },
            ];

            let router = new VueRouter({
                routes
            })
            new Vue({
                el: '#app',
                data: {},
                router
            })
        </script>
    </body>
</html>